<template>
    <div>
        <hd-tab :tabs="tabs"></hd-tab>
        <el-card class="box-card" shadow="never">
            <div slot="header" class="clearfix">
                <span>设置角色</span>
            </div>
            <el-form ref="form" :model="form" label-width="80px">
                <el-form-item label="角色名称">
                    <el-input v-model="form.title" placeholder="角色名称（中文）"></el-input>
                    <hd-error name="title"></hd-error>
                </el-form-item>
                <el-form-item label="角色标识">
                    <el-input v-model="form.name" placeholder="角色标识（英文）"></el-input>
                    <hd-error name="name"></hd-error>
                </el-form-item>
            </el-form>
            <el-button-group>
                <el-button type="primary" @click="onSubmit">保存</el-button>
            </el-button-group>
        </el-card>
    </div>
</template>

<script>
import tabs from './tabs'

const form = {name: '', title: ''}
export default {
    props: ['id'],
    route: false,
    data() {
        return {
            tabs,
            form
        }
    },
    async created() {
        if (this.id) {
            this.form = await this.axios.get(`admin/role/${this.id}`)
        }
    },
    methods: {
        async onSubmit() {
            const url = this.id ? `admin/role/${this.id}` : 'admin/role'
            await this.axios[this.id ? 'put' : 'post'](url, this.form)
            this.$router.push({name: 'admin.role.index'})
        }
    }
}
</script>

<style scoped>

</style>
